package com.yyl.keqiance;

import com.yyl.tcptest.SocketTest;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
public class ClientTest {
    public static void main(String[] args) {
        //1. 创建Socket对象
        //  public Socket(InetAddress address, int port)
        Socket socket = null;
        OutputStream outputStream = null;
        try {
            // socket = new Socket(InetAddress.getByName("localhost"),8888);
            socket = new Socket("localhost",8888);
            // 发送数据
            System.out.println("客户端开始发送消息");
           Scanner scanner = new Scanner(System.in);
           String con = scanner.next();
            // 获取一下输出流
             outputStream = socket.getOutputStream();
            outputStream.write(con.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            // 关闭输出流
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 关闭socket
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
